package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.domain.Subject;
import com.itheima.mapper.SubjectMapper;
import com.itheima.service.ISubjectService;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 专题表 服务实现类
 * </p>
 *
 * @author fukeke
 * @since 2022-11-11
 */
@DubboService
public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, Subject> implements ISubjectService {

    @Autowired
    SubjectMapper subjectMapper;

    @Override
    public PageBeanVo findByNameAndPage(Integer pageNum, Integer pageSize, String keyword) {
        LambdaQueryWrapper<Subject>lqw=new LambdaQueryWrapper<>();
        Page<Subject> page=new Page<>(pageNum,pageSize);

        lqw.eq(keyword!=null,Subject::getCategoryName,keyword);
         subjectMapper.selectPage(page,lqw);

         return new PageBeanVo(pageNum,pageSize,page.getTotal(),page.getRecords());
    }

    @Override
    public List<Subject> getAll() {
        return subjectMapper.selectList(null);
    }
}
